home *** CD-ROM | disk | FTP | other *** search
- /*
- ••••••••••••••••••••
- AliasBM.c
- David Surovell
-
- this file contains 2 routines to assist in the creation of
- gxBitmap shapes whose image data resides in an accessible
- file. The file should contain valid image data, and should be large
- enough to hold the enitre image as specified by the gxBitmap argument
- ••••••••••••••••••••
- */
-
- #include <Types.h>
- #include <Errors.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Files.h>
- #include <Aliases.h>
-
- #include "graphics types.h"
- #include "graphics errors.h"
- #include "graphics routines.h"
-
-
- gxShape CreateDiskBitmap(
- FSSpec *fsData,
- gxBitmap *targetBM );
- gxTag CreateBitmapAliasTag(
- FSSpec *bitmapFS,
- unsigned long fileOffset );
-
-
-
- gxShape CreateDiskBitmap(
- FSSpec *fsData,
- gxBitmap *targetBM )
- {
- gxBitmap localBM;
- gxShape targetShape;
- gxTag targetTag;
-
- if ((fsData == nil) || (targetBM == nil))
- return nil;
-
- targetShape = nil;
-
- targetTag = CreateBitmapAliasTag( fsData, 0L );
- if (targetTag != nil)
- {
- localBM = *targetBM;
- localBM.image = (Ptr)gxBitmapFileAliasImageValue;
- targetShape = GXNewBitmap( &localBM, nil );
-
- if (targetShape != nil)
- GXSetShapeTags( targetShape, gxBitmapFileAliasTagType, 1L, -1L, 1L, &targetTag );
- GXDisposeTag( targetTag );
- }
-
- return targetShape;
- }
-
-
- gxTag CreateBitmapAliasTag(
- FSSpec *bitmapFS,
- unsigned long fileOffset )
- {
- struct gxBitmapDataSourceAlias *aliasRecordPtr;
- gxTag targetTag;
- FSSpec targetFS;
- AliasHandle aliasHdl;
- OSErr iErr;
- long aliasSize, aliasRecordSize;
- Boolean wasChanged;
-
- targetTag = nil;
- aliasHdl = nil;
- aliasRecordPtr = nil;
-
- // create an alias and resolve it
- iErr = NewAlias( nil, bitmapFS, &aliasHdl );
- if (iErr == noErr)
- iErr = ResolveAlias( nil, aliasHdl, &targetFS, &wasChanged );
-
- // build up a compact representation for inclusion into a gxTag */
- if (iErr == noErr)
- {
- aliasSize = GetHandleSize( (Handle)aliasHdl );
- aliasRecordSize = aliasSize + 2 * sizeof( long );
- aliasRecordPtr = (struct gxBitmapDataSourceAlias*)NewPtr( aliasRecordSize );
- iErr = MemError();
- }
-
- // create the gxTag
- if (iErr == noErr)
- {
- // create gxBitmapDataSourceAlias with specified fileOffset
- // and appropriate aliasRecordSize and aliasRecord
- aliasRecordPtr->fileOffset = fileOffset;
- aliasRecordPtr->aliasRecordSize = aliasSize;
- BlockMove( *aliasHdl, &aliasRecordPtr->aliasRecord[0], aliasSize );
-
- targetTag = GXNewTag( gxBitmapFileAliasTagType, aliasRecordSize, aliasRecordPtr );
- }
-
- // clean up
- if (aliasHdl != nil)
- DisposeHandle( (Handle)aliasHdl );
- if (aliasRecordPtr != nil)
- DisposePtr( (Ptr)aliasRecordPtr );
-
- return targetTag;
- }
-
-
-
-